package com.ecable.action;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ecable.daoImpl.PackagesDaoImpl;
import com.ecable.daoImpl.ProfileDAO;
import com.ecable.exception.ConnectionException;
import com.ecable.exception.LoginException;
import com.ecable.util.UtilConstants;


public class AddPackageAction extends HttpServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String path = "";
		RequestDispatcher rd = null;

		boolean flag = false;
		String pname = request.getParameter("pname");
		String pdiscription = request.getParameter("pdiscription");
		int pamount = Integer.parseInt(request.getParameter("pamount"));
		try {
			flag = new PackagesDaoImpl().addPackage(pname, pdiscription, pamount);
		}
		catch (Exception le) {
			request.setAttribute("status", UtilConstants._INVALID_PACKAGE);
			rd = request.getRequestDispatcher(UtilConstants._ADD_PACKAGE_FAILED);
		}

		if (flag) {

			request.setAttribute("status",
					UtilConstants._PACKAGE_INSERTED_SUCCESS);
			path = UtilConstants._ADD_PACKAGE;

		} else {

			request
					.setAttribute("status",
							UtilConstants._ADD_PACKAGE_FAILED);
			path = UtilConstants._ADD_PACKAGE;

		}

		rd = request.getRequestDispatcher(path);

		rd.forward(request, response);
	}

}
